import {createWebHashHistory,createRouter} from 'vue-router'
import MenuBar from './menu-bar'


let recursion = (list) => {
let childrenlist = []
  list.forEach(ele => {
    childrenlist.push({
      path: ele.path,
      titel: ele.titel,
      component: () => import(ele.url),
      children: ele.children ? recursion(ele.children) : []
    })
  });
  return childrenlist // 递归子路由
}

// 格式处理
let getobj = ele => ({
  path: ele.path,
  titel: ele.titel,
  component: () => import(ele.url),
  children: ele.children ? recursion(ele.children) : []
})


let routes = []
MenuBar.forEach(ele => {routes.push(getobj(ele))});



const history = createWebHashHistory()
const router = createRouter({
  history,
  routes: routes
})



export default router